﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace LastoRevival.Service.Contracts.Models
{
	public class UserProfile
	{

		public UserProfileDetails Details { get; set; }
		private ForumAccessConfiguration forumAccess;


		private UserProfile()
		{
			Details = new UserProfileDetails();
			forumAccess = new ForumAccessConfiguration();
		}


		public static UserProfile Create(UserProfileDetails details, ForumAccessConfiguration forumAccess)
		{
			return new UserProfile { Details = details, forumAccess = forumAccess };
		}

		
		private bool HasForumRights(int forumID, ForumAccessType minAccessLevel)
		{
			if (Details.IsAdministrator)
			{
				return true; // admins can do all
			}

			if (!forumAccess.ContainsKey(forumID))
			{
				return false;
			}

			return (int)forumAccess[forumID] >= (int)minAccessLevel;
		}

		public bool CanViewForum(int forumID)
		{
			return HasForumRights(forumID, ForumAccessType.Readonly);
		}

		public bool CanCreateThread(int forumID)
		{
			return HasForumRights(forumID, ForumAccessType.FullPosting);
		}

		public bool CanReply(int forumID)
		{
			return HasForumRights(forumID, ForumAccessType.ReplyOnly);
		}

		public bool CanModerate(int forumID)
		{
			return HasForumRights(forumID, ForumAccessType.Moderation);
		}
	}
}
